package com.xzr.Service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xzr.Service.RbacManagerService;
import com.xzr.dao.RbacManagerDao;
import com.xzr.entity.RbacManager;
import com.xzr.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @Author：jojo
 * @Date：2022/2/21 15:44
 * @Description :TODO
 */
@Service
public class RbacManagerServiceImpl implements RbacManagerService {
    @Autowired(required = false)
    RbacManagerDao rbacManagerDao;
    @Override
    public ResultData findAll(int currentPage,int pageSize,RbacManager rbacManager) {
        PageHelper.startPage(currentPage,pageSize);
        List<RbacManager> list = rbacManagerDao.findAll(rbacManager);
        PageInfo<RbacManager> of = PageInfo.of(list);
        ResultData<PageInfo> result = new ResultData<>();
        result.setData(of);
        result.setCode(200);
        return result;

    }

    @Override
    public ResultData deletOne(int id) {
        int num = rbacManagerDao.deletOne(id);
        ResultData<Object> result = new ResultData<>();
        if (num > 0){
            result.setCode(200);
        }else{
            result.setCode(500);
        }
        return result;
    }

    @Override
    public ResultData addOne(RbacManager rbacManager) {
        int num = rbacManagerDao.addOne(rbacManager);
        ResultData<Object> result = new ResultData<>();
        if (num > 0){
            result.setCode(200);
        }else{
            result.setCode(500);
        }
        return result;
    }

    @Override
    public ResultData updataOne(RbacManager rbacManager) {
        int num = rbacManagerDao.updataOne(rbacManager);
        ResultData<Object> result = new ResultData<>();
        if (num > 0){
            result.setCode(200);
        }else{
            result.setCode(500);
        }
        return result;
    }
}
